/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tools;

import com.aptech.bluepumpkin.CommentsList;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Trong Nguyen
 */
public final class CommentDataModel extends ListDataModel<CommentsList> implements SelectableDataModel<CommentsList>, Serializable {

    private HashMap<Integer, CommentsList> maps = new HashMap<Integer, CommentsList>();

    public CommentDataModel(List<CommentsList> list) {
        super(list);
        buildHashMap(list);
    }

    public CommentDataModel() {
    }

    public void buildHashMap(List<CommentsList> list) {
        maps.clear();
        if (null == list || list.isEmpty()) {
            return;
        }

        for (CommentsList comment : list) {
            maps.put(comment.getId(), comment);

        }
    }

    @Override
    public Object getRowKey(CommentsList object) {
         if (null != object) {
            return object.getId();
        } else {
            return null;
        }
    }

    @Override
    public CommentsList getRowData(String rowKey) {
        Integer id = new Integer(rowKey);
        return maps.get(id);
    }
}
